home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9260 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  45 lines

  1. Newsgroups: comp.lang.asm.x86,comp.lang.c,comp.lang.c++
  2. Path: indra.com!sullivan
  3. From: sullivan@indra.com (Steve Sullivan)
  4. Subject: Catch Fixed Point Overflow in C or C++
  5. Message-ID: <DnJpxH.CDw.0.net@indra.com>
  6. Organization: Indra's Net - Public Internet Access
  7. Date: Thu, 29 Feb 1996 16:32:05 GMT
  8.  
  9. Is it possible to have a Pentium assembler routine set up so
  10. that fixed-point overflow in C or C++ is caught?  For example,
  11. would either of the following approaches work?
  12.  
  13. Approach 1:
  14.    /* here carryflag() is an asm routine to return the carry flag */
  15.    int sum, i, j;
  16.    long lprod, li, lj;
  17.    sum = i + j;
  18.    if ( carryflag()) printf("sum overflow occured\n");
  19.    lprod = li * lj;
  20.    if ( carryflag()) printf("prod overflow occured\n");
  21.  
  22. Approach 2:
  23.    int sum, i, j;
  24.    long lprod, li, lj;
  25.    setOverCheck();   /* this is an asm routine that enables
  26.                         "interrupt on overflow" */
  27.    try {
  28.       sum = i + j;      /* get exception if overflow occurs */
  29.       lprod = li * lj;  /* get exception if overflow occurs */
  30.    }
  31.    catch (const char * msg) { printf("overflow occured in %s\n", msg); }
  32.  
  33. Approach 2 would be much preferred, if possible, since it doesn't
  34. require checking after each operation as in approach 1.
  35.  
  36. Where could I find such asm code, or references on how to write it?
  37. I don't know x86 asm, but if need be I'll learn it (sigh!).
  38. Also, would similar approaches work to detect floating point exceptions?
  39.  
  40. Many thanks for any suggestions --
  41.  
  42. Steve Sullivan
  43.  
  44.  
  45.